#include "stdafx.h"
#include "Gorilla.h"
#include "mainMenu.h"
#include <string.h>
#include <stdio.h>

using namespace Ogre;

void mainMenu::showOptions()
{
engine->play2D("../../media/oMopen.wav", false, false, false, irrklang::ESM_NO_STREAMING, false);

atm=380;
currentMenu=TOOM;

oMenuState=AA;

std::vector<Gorilla::Caption*>::iterator myIterator;
for(myIterator = oMenuButtons.begin(); 
myIterator != oMenuButtons.end();
myIterator++)
{
	Gorilla::Caption* c=(*myIterator);
	c->colour(Ogre::ColourValue(1,1,1,0.3));
}

cOptionButton=firstOptionButton;
cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,1));
cOptionButtonA=firstOptionButtonA;
cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,1));

}

void mainMenu::saveCfg()
{
 FILE * pFile;
 pFile = fopen ("config.ini" , "w");
 char * cstr;
fputs ("[renderer]\n" , pFile);
fputs ("width = " , pFile);
std::string a=Ogre::StringConverter::toString(gConfig->width)+"\n";
 cstr = new char [a.size()+1];
 strcpy (cstr, a.c_str());
 fputs (cstr, pFile);
fputs ("height = " , pFile);
delete cstr;
std::string a2=Ogre::StringConverter::toString(gConfig->height)+"\n";
 cstr = new char [a2.size()+1];
 strcpy (cstr, a2.c_str());
 fputs (cstr, pFile);
fputs ("shr = " , pFile);
delete cstr;
std::string a3=Ogre::StringConverter::toString(gConfig->shadowR)+"\n";
 cstr = new char [a3.size()+1];
 strcpy (cstr, a3.c_str());
 fputs (cstr, pFile);
fputs ("shf = " , pFile);
delete cstr;
std::string a4=Ogre::StringConverter::toString(gConfig->shadowF)+"\n";
 cstr = new char [a4.size()+1];
 strcpy (cstr, a4.c_str());
 fputs (cstr, pFile);
fputs ("pp = " , pFile);
delete cstr;
std::string a5=Ogre::StringConverter::toString(gConfig->postP)+"\n";
 cstr = new char [a5.size()+1];
 strcpy (cstr, a5.c_str());
 fputs (cstr, pFile);
 delete cstr;
fclose (pFile);
}
void mainMenu::closeOptions()
{
engine->play2D("../../media/oMopen.wav", false, false, false, irrklang::ESM_NO_STREAMING, false);

atm=380;
currentMenu=FROM;
//oMenuState=RES;

std::vector<Gorilla::Caption*>::iterator myIterator;

for(myIterator = oMenuButtons.begin(); 
myIterator != oMenuButtons.end();
myIterator++)
{
	Gorilla::Caption* c=(*myIterator);
	c->colour(Ogre::ColourValue(1,1,1,0.3));
}

saveCfg();
}

int mainMenu::pressedKey(const OIS::KeyEvent &arg)
{

	if(currentMenu==MAINM && !moving){
		switch (arg.key)
		{
			case OIS::KC_LEFT: 
				if(!moving)
				{
				menuMovingDir=1;
				moving=true;
				mMenuState=mMenuState->prevState;
				}
			    break;
		    case OIS::KC_RIGHT: 
			   	if(!moving)
				{
			    menuMovingDir=-1;
			    moving=true;
		    	mMenuState=mMenuState->nextState;
				}
			    break;

		    case OIS::KC_RETURN: 
				if(mMenuState->mState==QUIT)
				{
				saveCfg();
				return 1;
				}
				if(mMenuState->mState==OPTIONS)
				{
				showOptions();
				}
			    break;
           default:
              break;
		}
	}
else
if(currentMenu==OPTIONSM)
{
switch (arg.key)
		{
		   case OIS::KC_UP: 
			   /*oMenuState=oMenuState->prevState;
			   cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,0.3));
			   cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,0.3));
			   cOptionButton=cOptionButton->prevState;
			   cOptionButtonA=cOptionButtonA->prevState;
			   cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,1));
			   cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,1));*/
			   break;
		   case OIS::KC_DOWN: 
			   /*oMenuState=oMenuState->nextState;
			   cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,0.3));
			   cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,0.3));
			   cOptionButton=cOptionButton->nextState;
			   cOptionButtonA=cOptionButtonA->nextState;
			   cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,1));
			   cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,1));*/
			   break;
		   case OIS::KC_LEFT: 
			   /*if(oMenuState->mState==AA)
			   {if(gConfig->aa) cOptionButtonA->mButton->text("Low"); else cOptionButtonA->mButton->text("High");
			   gConfig->aa=!gConfig->aa;}
			   if(oMenuState->mState==SHR)
			   {if(gConfig->godRay) cOptionButtonA->mButton->text("Low"); else cOptionButtonA->mButton->text("High");
			   gConfig->godRay=!gConfig->godRay;}
			   if(oMenuState->mState==SHF)
			   {if(gConfig->hdr) cOptionButtonA->mButton->text("Low"); else cOptionButtonA->mButton->text("High");
			   gConfig->hdr=!gConfig->hdr;}
			   if(oMenuState->mState==PP)
			   {if(gConfig->vsync) cOptionButtonA->mButton->text("Low"); else cOptionButtonA->mButton->text("High");
			   gConfig->vsync=!gConfig->vsync;}*/
			   break;
		   case OIS::KC_RIGHT: 
			   /*if(oMenuState->mState==AA)
			   {if(gConfig->aa) cOptionButtonA->mButton->text("Low"); else cOptionButtonA->mButton->text("High");
			   gConfig->aa=!gConfig->aa;}
			   if(oMenuState->mState==SHR)
			   {if(gConfig->godRay) cOptionButtonA->mButton->text("Low"); else cOptionButtonA->mButton->text("High");
			   gConfig->godRay=!gConfig->godRay;}
			   if(oMenuState->mState==SHF)
			   {if(gConfig->hdr) cOptionButtonA->mButton->text("Low"); else cOptionButtonA->mButton->text("High");
			   gConfig->hdr=!gConfig->hdr;}
			   if(oMenuState->mState==PP)
			   {if(gConfig->vsync) cOptionButtonA->mButton->text("Low"); else cOptionButtonA->mButton->text("High");
			   gConfig->vsync=!gConfig->vsync;}*/
			   break;
		   case OIS::KC_RETURN: 
			   break;
		   case OIS::KC_BACK: 
			   // Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("sfs",Ogre::LML_NORMAL);
			    closeOptions();
			   break;

           default:
              break;
		}
}

return 0;
}

mainMenu::mainMenu(Ogre::SceneManager *mSceneM, Ogre::Camera* mCam,Ogre::RenderWindow* mWin,Ogre::RenderSystem* rs,irrklang::ISoundEngine* eng)
{
engine=eng;

gConfig=new GameConfig();
Ogre::ConfigFile cfgFile;
cfgFile.loadDirect("config.ini");
std::string wString = cfgFile.getSetting("width", "renderer");
std::string hString = cfgFile.getSetting("height", "renderer");
std::string srString = cfgFile.getSetting("shr", "renderer");
std::string sfString = cfgFile.getSetting("shf", "renderer");
std::string ppString = cfgFile.getSetting("pp", "renderer");
gConfig->width=Ogre::StringConverter::parseInt(wString);
gConfig->height=Ogre::StringConverter::parseInt(hString);
gConfig->shadowR=Ogre::StringConverter::parseBool(srString);
gConfig->shadowF=Ogre::StringConverter::parseBool(sfString);
gConfig->postP=Ogre::StringConverter::parseBool(ppString);

Ogre::ConfigOptionMap& CurrentRendererOptions = rs->getConfigOptions();
Ogre::ConfigOptionMap::iterator configItr = CurrentRendererOptions.begin();
while( configItr != CurrentRendererOptions.end() ) 
{
  if( (configItr)->first == "Video Mode" )
  {
     // Store Available Resolutions
          mFoundResolutions = ((configItr)->second.possibleValues);
  }
  configItr++;
}

int i=mFoundResolutions.size();
std::string currentR=Ogre::StringConverter::toString(gConfig->width)+"x"+Ogre::StringConverter::toString(gConfig->height);

resLoop* trLoop=resolutionsLoop= new resLoop();
resLoop* trLoopC=resolutionsLoop;
std::string s=mFoundResolutions.at(i/2);

char * cstr;
cstr = new char [s.size()+1];
strcpy (cstr, s.c_str());
std::string s1=strtok(cstr," ");
strtok(NULL," ");
std::string s2=strtok(NULL," ");
std::string res=s1+"x"+s2;
resolutionsLoop->res=new std::string(res);
resolutionsLoop->w=Ogre::StringConverter::parseInt(s1);
resolutionsLoop->h=Ogre::StringConverter::parseInt(s2);

for(int o=(i/2)+1;o<i;o++)
{
        std::string s=mFoundResolutions.at(o);
        char * cstr;
        cstr = new char [s.size()+1];
        strcpy (cstr, s.c_str());


        std::string s1=strtok(cstr," ");
        strtok(NULL," ");
        std::string s2=strtok(NULL," ");
        std::string res=s1+"x"+s2;
        resLoop* trLoopN= new resLoop();
		trLoopN->w=Ogre::StringConverter::parseInt(s1);
		trLoopN->h=Ogre::StringConverter::parseInt(s2);
	    trLoopN->res=new std::string(res);
        if(Ogre::StringUtil::match(currentR,res)) trLoopC=trLoopN;
        trLoopN->prevRes=trLoop;
        trLoop->nextRes=trLoopN;
        trLoop=trLoopN;
}
resolutionsLoop->prevRes=trLoop;
trLoop->nextRes=resolutionsLoop;
resolutionsLoop=trLoopC;


for(int o=(i/2);o<i;o++)
{
Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(*resolutionsLoop->res,Ogre::LML_NORMAL);
resolutionsLoop=resolutionsLoop->nextRes;
}

mMenuState= new mMenuLoop();
mMenuLoop* mMenuState0= new mMenuLoop();
mMenuLoop* mMenuState2= new mMenuLoop();
mMenuState->mState=START;
mMenuState->nextState=mMenuState2;
mMenuState->prevState=mMenuState0;
mMenuState0->mState=QUIT;
mMenuState0->nextState=mMenuState;
mMenuState0->prevState=mMenuState2;
mMenuState2->mState=OPTIONS;
mMenuState2->nextState=mMenuState0;
mMenuState2->prevState=mMenuState;

oMenuState= AA;

currentMenu=MAINM;

moving=false;
atm=0;
menuMovingDir=1;
mSceneMgr=mSceneM;
mCamera=mCam;
mWindow=mWin;
mSilverback = new Gorilla::Silverback();
mSilverback->loadAtlas("dejavu");
mScreen = mSilverback->createScreen(mCamera->getViewport(), "dejavu");
mScreen->setOrientation(Ogre::OrientationMode::OR_DEGREE_0);
Ogre::Real vpW = mScreen->getWidth(), vpH = mScreen->getHeight();

mLayer = mScreen->createLayer(0);

mouseLayer=mScreen->createLayer(1);
mousePointer = mouseLayer->createRectangle(0,0,41,42);
mousePointer->background_image("mousepointer");
mousePointer->no_background();
fpsCaption = mouseLayer->createCaption(48, 50, 5, "007");
fpsCaption->size(1500,50);
fpsCaption->colour(Ogre::ColourValue(0,255,0));
fpsCaption->align(Gorilla::TextAlign_Right);

debugCaption = mouseLayer->createCaption(48, 50, 5, "007");
debugCaption->size(1500,50);
debugCaption->colour(Ogre::ColourValue(0,0,255));
debugCaption->align(Gorilla::TextAlign_Left);

mousePointer->yes_background(1);
}

void mainMenu::setMainMenu()
{
mLayer->show();
Gorilla::Caption* caption = mLayer->createCaption(48, 690, 900 , "Start");
caption->size(300,50);
caption->colour(Ogre::ColourValue(1,1,1,1));
caption->align(Gorilla::TextAlign_Centre);
mMenuButtons.push_back(caption);
caption = mLayer->createCaption(48, 1339.5, 900 , "Options");
caption->size(300,50);
caption->colour(Ogre::ColourValue(1,1,1,0.3));
caption->align(Gorilla::TextAlign_Centre);
mMenuButtons.push_back(caption);
caption = mLayer->createCaption(48, 40.5, 900 , "Quit");
caption->size(300,50);
caption->colour(Ogre::ColourValue(1,1,1,0.3));
caption->align(Gorilla::TextAlign_Centre);
mMenuButtons.push_back(caption);

cOptionButton=firstOptionButton=new buttonLoop();
buttonLoop* cOptionButton2=new buttonLoop();
buttonLoop* cOptionButton3=new buttonLoop();
buttonLoop* cOptionButton4=new buttonLoop();
cOptionButton->prevState=cOptionButton4;
cOptionButton->nextState=cOptionButton2;
cOptionButton2->prevState=cOptionButton;
cOptionButton2->nextState=cOptionButton3;
cOptionButton3->prevState=cOptionButton2;
cOptionButton3->nextState=cOptionButton4;
cOptionButton4->prevState=cOptionButton3;
cOptionButton4->nextState=cOptionButton;
caption = mLayer->createCaption(48, 350, 1060 , "Resolution");
caption->size(600,50);
caption->colour(Ogre::ColourValue(1,1,1,0.3));
caption->align(Gorilla::TextAlign_Left);
oMenuButtons.push_back(caption);
cOptionButton->mButton=caption;
caption = mLayer->createCaption(48, 350, 1150 , "Shadow resolution");
caption->size(601,50);
caption->colour(Ogre::ColourValue(1,1,1,0.3));
caption->align(Gorilla::TextAlign_Left);
oMenuButtons.push_back(caption);
cOptionButton2->mButton=caption;
caption = mLayer->createCaption(48, 350, 1240 , "Shadow filtering");
caption->size(602,50);
caption->colour(Ogre::ColourValue(1,1,1,0.3));
caption->align(Gorilla::TextAlign_Left);
oMenuButtons.push_back(caption);
cOptionButton3->mButton=caption;
caption = mLayer->createCaption(48, 350, 1330 , "Post Processing");
caption->size(603,50);
caption->colour(Ogre::ColourValue(1,1,1,0.3));
caption->align(Gorilla::TextAlign_Left);
oMenuButtons.push_back(caption);
cOptionButton4->mButton=caption;

cOptionButtonA=firstOptionButtonA=new buttonLoop();
buttonLoop* cOptionButtonA2=new buttonLoop();
buttonLoop* cOptionButtonA3=new buttonLoop();
buttonLoop* cOptionButtonA4=new buttonLoop();
cOptionButtonA->prevState=cOptionButtonA4;
cOptionButtonA->nextState=cOptionButtonA2;
cOptionButtonA2->prevState=cOptionButtonA;
cOptionButtonA2->nextState=cOptionButtonA3;
cOptionButtonA3->prevState=cOptionButtonA2;
cOptionButtonA3->nextState=cOptionButtonA4;
cOptionButtonA4->prevState=cOptionButtonA3;
cOptionButtonA4->nextState=cOptionButtonA;

ri= mLayer->createRectangle(683,1085,217,35);
ri->background_image("restartimage");
ri->no_background();

std::string resolutionStr=Ogre::StringConverter::toString(gConfig->width)+"x"+Ogre::StringConverter::toString(gConfig->height);
caption = mLayer->createCaption(48, 1000, 1060 , resolutionStr);
caption->size(350,50);
caption->colour(Ogre::ColourValue(1,1,1,0.3));
caption->align(Gorilla::TextAlign_Left);
oMenuButtons.push_back(caption);
cOptionButtonA->mButton=caption;
if(gConfig->shadowR) 
caption = mLayer->createCaption(48, 1000, 1150 , "High"); else 
caption = mLayer->createCaption(48, 1000, 1150 , "Low");
caption->size(351,50);
caption->colour(Ogre::ColourValue(1,1,1,0.3));
caption->align(Gorilla::TextAlign_Left);
oMenuButtons.push_back(caption);
cOptionButtonA2->mButton=caption;
if(gConfig->shadowF) 
caption = mLayer->createCaption(48, 1000, 1240 , "High"); else
caption = mLayer->createCaption(48, 1000, 1240 , "Low");
caption->size(352,50);
caption->colour(Ogre::ColourValue(1,1,1,0.3));
caption->align(Gorilla::TextAlign_Left);
oMenuButtons.push_back(caption);
cOptionButtonA3->mButton=caption;
if(gConfig->postP) 
caption = mLayer->createCaption(48, 1000, 1330 , "High"); else
caption = mLayer->createCaption(48, 1000, 1330 , "Low");
caption->size(353,50);
caption->colour(Ogre::ColourValue(1,1,1,0.3));
caption->align(Gorilla::TextAlign_Left);
oMenuButtons.push_back(caption);
cOptionButtonA4->mButton=caption;
}

void mainMenu::mouseMoveUpdate(int x,int y)
{
	Vector2 pos=mousePointer->position();
	mousePointer->position(Math::Clamp<int>(pos.x+x,0,1680-15),Math::Clamp<int>(pos.y+y,0,1050-22));

	if(currentMenu==OPTIONSM)
	{
	std::vector<Gorilla::Caption*>::iterator myIterator;
	for(myIterator = oMenuButtons.begin();myIterator != oMenuButtons.end();myIterator++)
		{
			Gorilla::Caption* c=(*myIterator);
			if(c->intersects(pos))
			{
				if(!(cOptionButton->mButton->width()==c->width() || cOptionButtonA->mButton->width()==c->width()))
				{

				if(c->width()==600 || c->width()==350)
					{
					oMenuState=AA;
				   cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,0.3));
				   cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,0.3));

				   while(cOptionButton->mButton->width()!=600)
				   cOptionButton=cOptionButton->prevState;
				   while(cOptionButtonA->mButton->width()!=350)
				   cOptionButtonA=cOptionButtonA->prevState;
				   cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,1));
				   cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,1));

				   engine->play2D("../../media/oMmove.wav", false, false, false, irrklang::ESM_NO_STREAMING, false);
					}

					if(c->width()==601 || c->width()==351)
					{
					oMenuState=SHR;
				   cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,0.3));
				   cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,0.3));

				   while(cOptionButton->mButton->width()!=601)
				   cOptionButton=cOptionButton->prevState;
				   while(cOptionButtonA->mButton->width()!=351)
				   cOptionButtonA=cOptionButtonA->prevState;
				   cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,1));
				   cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,1));

				   engine->play2D("../../media/oMmove.wav", false, false, false, irrklang::ESM_NO_STREAMING, false);
					}

					if(c->width()==602 || c->width()==352)
					{
					oMenuState=SHF;
				   cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,0.3));
				   cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,0.3));

				   while(cOptionButton->mButton->width()!=602)
				   cOptionButton=cOptionButton->prevState;
				   while(cOptionButtonA->mButton->width()!=352)
				   cOptionButtonA=cOptionButtonA->prevState;
				   cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,1));
				   cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,1));

				   engine->play2D("../../media/oMmove.wav", false, false, false, irrklang::ESM_NO_STREAMING, false);
					}

					if(c->width()==603 || c->width()==353)
					{
					oMenuState=PP;
				   cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,0.3));
				   cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,0.3));

				   while(cOptionButton->mButton->width()!=603)
				   cOptionButton=cOptionButton->prevState;
				   while(cOptionButtonA->mButton->width()!=353)
				   cOptionButtonA=cOptionButtonA->prevState;
				   cOptionButton->mButton->colour(Ogre::ColourValue(1,1,1,1));
				   cOptionButtonA->mButton->colour(Ogre::ColourValue(1,1,1,1));

				   engine->play2D("../../media/oMmove.wav", false, false, false, irrklang::ESM_NO_STREAMING, false);
					}

				}
			}
		}
	}

}

int mainMenu::mainMenuPressed()
	{
		Vector2 mPos=mousePointer->position();

		std::vector<Gorilla::Caption*>::iterator myIterator;
		for(myIterator = mMenuButtons.begin(); 
        myIterator != mMenuButtons.end();
        myIterator++)
		{
			Gorilla::Caption* c=(*myIterator);
			if(c->intersects(mPos))
			{
				if(currentMenu==MAINM)
				{
					if(!moving)
					{
						if((mMenuState->mState==START && Ogre::StringUtil::match(c->text(),"Quit")) ||
							(mMenuState->mState==OPTIONS && Ogre::StringUtil::match(c->text(),"Start"))||
							(mMenuState->mState==QUIT && Ogre::StringUtil::match(c->text(),"Options"))
							)
							{
							menuMovingDir=1;
							moving=true;
							mMenuState=mMenuState->prevState;
							engine->play2D("../../media/mMchange.wav", false, false, false, irrklang::ESM_NO_STREAMING, false);
							}
						else
						if((mMenuState->mState==START && Ogre::StringUtil::match(c->text(),"Options")) ||
							(mMenuState->mState==OPTIONS && Ogre::StringUtil::match(c->text(),"Quit"))||
							(mMenuState->mState==QUIT && Ogre::StringUtil::match(c->text(),"Start"))
							)
							{
							menuMovingDir=-1;
							moving=true;
							mMenuState=mMenuState->nextState;
							engine->play2D("../../media/mMchange.wav", false, false, false, irrklang::ESM_NO_STREAMING, false);
							}
						else
						if(Ogre::StringUtil::match(c->text(),"Quit"))
						{
							return 3;
						}
						else
						if(Ogre::StringUtil::match(c->text(),"Start"))
						{
							mMenuButtons.clear();
							mLayer->hide();
							mLayer->destroyAllCaptions();
							mousePointer->no_background();
							return 1;
						}
						else
						if(mMenuState->mState==OPTIONS)
						{
						showOptions();
						}
					}
				}
				else
				if(currentMenu==OPTIONSM)
				{
					if(mMenuState->mState==OPTIONS)
					{
					closeOptions();
					}
				}
			}
		}

		for(myIterator = oMenuButtons.begin(); 
        myIterator != oMenuButtons.end();
        myIterator++)
		{
			Gorilla::Caption* c=(*myIterator);
			if(c->intersects(mPos))
			{
				if(currentMenu==OPTIONSM)
				{

					if(c->width()==600 || c->width()==350)
					{
					resolutionsLoop=resolutionsLoop->nextRes; cOptionButtonA->mButton->text(*resolutionsLoop->res);
					gConfig->height=resolutionsLoop->h;  gConfig->width=resolutionsLoop->w;
					ri->yes_background(1);
					engine->play2D("../../media/oMclick.wav", false, false, false, irrklang::ESM_NO_STREAMING, false);
					}
					if(c->width()==601 || c->width()==351)
					{
					if(gConfig->shadowR) 
					{cOptionButtonA->mButton->text("Low"); mSceneMgr->setShadowTextureSettings(512,4, PF_FLOAT32_R);}
					else 
					{cOptionButtonA->mButton->text("High"); mSceneMgr->setShadowTextureSettings(1024,4, PF_FLOAT32_R);}
					gConfig->shadowR=!gConfig->shadowR;
								HighLevelGpuProgramPtr gpuProgram = HighLevelGpuProgramManager::getSingleton().getByName("diffuse_ps_bop");
			gpuProgram->setSourceFile("general_bop2.cg");
			gpuProgram->reload();
					engine->play2D("../../media/oMclick.wav", false, false, false, irrklang::ESM_NO_STREAMING, false);
					}
					if(c->width()==602 || c->width()==352)
					{
					if(gConfig->shadowF) cOptionButtonA->mButton->text("Low"); else cOptionButtonA->mButton->text("High");
					gConfig->shadowF=!gConfig->shadowF;
					engine->play2D("../../media/oMclick.wav", false, false, false, irrklang::ESM_NO_STREAMING, false);
					}
					if(c->width()==603 || c->width()==353)
					{
					if(gConfig->postP) cOptionButtonA->mButton->text("Low"); else cOptionButtonA->mButton->text("High");
					gConfig->postP=!gConfig->postP;
					engine->play2D("../../media/oMclick.wav", false, false, false, irrklang::ESM_NO_STREAMING, false);
					}
				}
			}
		}
		return 0;
	}

void mainMenu::updateFPS(Ogre::Real value)
{

	fpsCaption->text(Ogre::StringConverter::toString(mWindow->getLastFPS()));
	debugCaption->text(Ogre::StringConverter::toString(value));
}

void mainMenu::updateMenu(Ogre::Real evt)
{
fpsCaption->text(Ogre::StringConverter::toString((int)mWindow->getStatistics().lastFPS));

	if(currentMenu==TOOM)
	{
	Real rotSpeed=evt*1100;
	atm=atm-rotSpeed;
		if(atm<=0)
		{
		currentMenu=OPTIONSM;
		rotSpeed=rotSpeed+atm;
		atm=0; 
		}

		std::vector<Gorilla::Caption*>::iterator myIterator;

			for(myIterator = mMenuButtons.begin(); 
			myIterator != mMenuButtons.end();
			myIterator++)
			{
				Gorilla::Caption* c=(*myIterator);
				c->top(c->top()-rotSpeed);	
			}

			for(myIterator = oMenuButtons.begin(); 
			myIterator != oMenuButtons.end();
			myIterator++)
			{
				Gorilla::Caption* c=(*myIterator);
				c->top(c->top()-rotSpeed);	
				
			}

			ri->top(ri->top()-rotSpeed);	

	}
	else
	if(currentMenu==FROM)
	{
	Real rotSpeed=evt*1100;
	atm=atm-rotSpeed;
		if(atm<=0)
		{
		currentMenu=MAINM;
		rotSpeed=rotSpeed+atm;
		atm=0; 
		}

		std::vector<Gorilla::Caption*>::iterator myIterator;

			for(myIterator = mMenuButtons.begin(); 
			myIterator != mMenuButtons.end();
			myIterator++)
			{
				Gorilla::Caption* c=(*myIterator);
				c->top(c->top()+rotSpeed);	
			}

			for(myIterator = oMenuButtons.begin(); 
			myIterator != oMenuButtons.end();
			myIterator++)
			{
				Gorilla::Caption* c=(*myIterator);
				c->top(c->top()+rotSpeed);	
			}

			ri->top(ri->top()+rotSpeed);	

	}
	else
	if(moving)
		{
		Real rotSpeed=evt*1400;
		atm=atm+rotSpeed;
		if(atm>=666)
		{
		moving=false;
		rotSpeed=rotSpeed-(atm-666);
		atm=0; 
		}

		std::vector<Gorilla::Caption*>::iterator myIterator;
			for(myIterator = mMenuButtons.begin(); 
			myIterator != mMenuButtons.end();
			myIterator++)
			{
				//1680+2*309, roz 766
				Gorilla::Caption* c=(*myIterator);
				c->left(c->left()+rotSpeed*menuMovingDir);
				
				if(c->left()>=1689 && menuMovingDir==1)
				{
					c->left(-309+(c->left()-1689));
					
				}
				if(c->left()<=-309  && menuMovingDir==-1)
					c->left(1689-(-309-c->left()));

				Real alpha=1-Math::Abs((c->left()-690)/999);
				c->colour(Ogre::ColourValue(1,1,1,alpha));
		}
}

}